<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>医疗器械事件上报表</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <script src="../layui/layui.js"></script>
    <style>
        td{
            padding-left: 10px;
            padding-bottom: 5px;
            padding-right: 20px;
            padding-top: 10px;
        }
    </style>
</head>
<body>
<form class="layui-form" lay-filter="FormLoad">
    <table border="1px" width="100%" cellpadding="0">
        <tr >
            <td colspan="4" style="text-align: center; height: 50px"> <span style=" font-size: 20px">医疗器械不良事件报告表</span> </td>
        </tr>
        <tr>
            <div class="layui-form-item">
                <td>
                    报告日期：
                </td>
                <td colspan="1">
                    <input type="text" name="report_date" id="report_date" placeholder="" class="layui-input">
                </td>

                <td>
                    报告来源：
                </td>

                <td colspan="1">
                    <input type="text" name="report_source" placeholder="" class="layui-input">
                </td>
            </div>
        </tr>
        <tr>
            <div class="layui-form-item">
                <td>
                    报告人：
                </td>
                <td colspan="1">
                    <input type="text" name="reporter" placeholder="" class="layui-input">
                </td>

                <td>
                    科室名称：
                </td>

                <td colspan="1">
                    <input type="text" name="reporter_department" placeholder="" class="layui-input">
                </td>
            </div>
        </tr>
        <tr>
            <td colspan="4" style="height: 50px; text-align: center" >
                患者资料
            </td>
        </tr>
        <tr>
            <div class="layui-form-item">
                <td>
                    姓名:
                </td>
                <td>
                    <input type="text" name="patient_name" placeholder="" class="layui-input">
                </td>

                <td>
                    年龄
                </td>

                <td>
                    <input type="text" name="patient_age" placeholder="" class="layui-input">
                </td>
            </div>
        </tr>
        <tr>
            <div class="layui-form-item">
                <td>
                    性别：
                </td>
                <td colspan="1">

                    <select name="patient_sex" lay-verify="required">
                        <option value=""></option>
                        <option value="男">男</option>
                        <option value="女">女</option>
                    </select>
                </td>
                <td>
                    住院号
                </td>
                <td>
                    <div class="layui-input-inline" >
                        <input type="text" name="patient_num" placeholder="" class="layui-input">
                    </div>
                    <div class="layui-input-inline">
                        <button class="layui-btn layui-btn layui-btn-sm layui-btn-normal"  id="xuanran"  >+</button>
                    </div>
                </td>

            </div>
        </tr>
        </tr>
        <div class="layui-form-item">
            <td>
                预期治疗疾病或作用
            </td>
            <td colspan="3">
                <textarea name="expect_treat_affect" style="height: 120px" required lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea>
            </td>
        </div>
        </tr>
        <tr>
            <td colspan="4" style="height: 50px; text-align: center" >
                不良事件情况
            </td>
        </tr>
        <tr>
            <div class="layui-form-item">
                <td colspan="1" >
                    出现不良反应医疗器械品牌
                </td>
                <td colspan="1">
                    <input type="text" name="apparatus_brand" placeholder="" class="layui-input">
                </td>
                <td>
                    出现不良反应医疗器械名称
                </td>
                <td colspan="1">
                    <input type="text" name="apparatus_name" placeholder="" class="layui-input">
                </td>
            </div>
        </tr>
        <tr>
            <div class="layui-form-item">
                <td>
                    出现不良反应医疗器械批号
                </td>
                <td colspan="1">
                    <input type="text" name="apparatus_num" placeholder="" class="layui-input">
                </td>
                <td></td> <td></td>
            </div>
        </tr>
        <div class="layui-form-item">
            <td>
                事件主要陈述及表现
            </td>
            <td colspan="3">
                <textarea name="bad_event_main_declare" style="height: 120px"  lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea>
            </td>
        </div>
        </tr>
        <tr>
            <div class="layui-form-item">
                <td colspan="1">
                    事件发生日期
                </td>
                <td colspan="1">
                    <input type="text" name="event_happen_time" autocomplete="off" id="event_happen_time" class="layui-input">
                </td>
                <td colspan="1">
                    发生或者知悉时间
                </td>
                <td colspan="1">
                    <input type="text" name="reporter_know_time" autocomplete="off" id="reporter_know_time" class="layui-input">
                </td>
            </div>
        </tr>
        <tr style="font-size: 20px">
            <div class="layui-form-item">
                <td colspan="1"> 事件后果及处理措施
                </td>
                <td colspan="3">
                    <textarea name="bad_event_ending" style="height: 120px" required lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea>
                </td>
            </div>
        </tr>
        <tr>
            <td colspan="4">
                （外科治疗避免上述永久损伤: 可能导致机体功能机构永久性损伤： 机体功能机构永久性损伤：至少包括器械使用时间，使用目的，使用依据，使用情况，出现的不良时间情况，对受害者影响。采取的治疗措施，器械联合使用情况）
            </td>
        </tr>
    </table>
    <div class="layui-form-item">
        <div class="layui-input-block" style="text-align: center; margin-top: 50px">
            <button class="layui-btn" lay-submit lay-filter="YiLiaoqx">立即提交</button>
            <button class="layui-btn" lay-submit lay-filter="save">保存</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
<script>

    function getQueryVariable(variable)
    {
        let query = window.location.search.substring(1);
        let vars = query.split("&");
        for (let i=0;i<vars.length;i++) {
            let pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
        }
        return(false);
    }


    layui.use(['laydate','jquery','form','layedit','layer','table','laytpl'], function() {
        let $ = layui.jquery;
        let form = layui.form;
        let laydate = layui.laydate;
        var layer = layui.layer;
        var router = layui.router();
        laydate.render({
            elem: '#reporter_know_time' //指定元素
            , type: 'date'
        });
        laydate.render({
            elem: '#event_happen_time' //指定元素
            , type: 'date'
        });
        laydate.render({
            elem: '#report_date' //指定元素
            , type: 'date'
        });

        form.render();
        // 获取地址的中的值
        let user_code=decodeURIComponent(getQueryVariable("user_code"));
        let user_name=decodeURIComponent(getQueryVariable("user_name"));
        let dept_code=decodeURIComponent(getQueryVariable("dept_code"));
        let dept_name=decodeURIComponent(getQueryVariable("dept_name"));
        // layui data 保存数据
        if( user_code=="undefined"){
            console.log(layui.data('user').userinfo.user_name)
        } else{
            console.log(user_code);
            console.log("地址有值")
            layui.data('user', {
                key: 'userinfo',
                value:
                    {
                        user_name: user_name,
                        user_code: user_code,
                        dept_code:dept_code,
                        dept_name:dept_name
                    }
            });
            console.log(layui.data('user').userinfo.user_name)
        }
        var month=parseInt(1)+parseInt(new Date().getMonth())
        //渲染 上报人和上报人单位
        form.val("FormLoad",{
            "reporter": layui.data('user').userinfo.user_name.replace(/\"/g, "") ,
            "reporter_department":layui.data('user').userinfo.dept_name.replace(/\"/g, ""),
            "report_date": new Date().getFullYear()+"-"+month+"-"+ new Date().getDate()
        })

        //渲染按钮监听事件
        $("#xuanran").click(function() {
            let data_init = form.val("FormLoad");
            $.ajax({
                url:'/event/event_patient?'+'in_his_no='+data_init.patient_num,
                type:"post",
                success:function (data){
                    let json = JSON.parse(data);
                    console.log(json.data[0]);
                    console.log(json.data[0].surgery_time);
                    form.val("FormLoad",{
                        "patient_name": json.data[0].name,
                        "patient_sex": json.data[0].gender,
                        "patient_age": json.data[0].age,
                        "patient_hospitalized_time":json.data[0].in_time,
                        "patient_num":data_init.patient_num,
                        // "patient_bed_num":null,
                        "patient_operation_time": json.data[0].surgery_time,
                        "patient_main_doctor":json.data[0].doc_in_charge,
                    })
                    form.render();
                }
            })
        })

        // submit 提交事件监听
        form.on('submit(YiLiaoqx)', function(data) {

            layer.confirm('确定提交吗？', {
                btn: ['确认', '取消'] //按钮
            }, function () {
                $.ajax({
                    url: '/event/event_insert',
                    type: "POST",
                    data:{
                        "reporter_code":layui.data('user').userinfo.user_code,
                        "reporter_name":layui.data('user').userinfo.user_name,
                        "dept_code":layui.data('user').userinfo.dept_code,
                        "dept_name":layui.data('user').userinfo.dept_name,
                        "event_code":6,
                        "report_date":data.field.report_date,
                        "report_source":data.field.report_source,
                        "reporter":data.field.reporter,
                        "reporter_department":data.field.reporter_department,
                        "patient_name":data.field.patient_name,
                        "patient_age":data.field.patient_age,
                        "patient_sex":data.field.patient_sex,
                        "expect_treat_affect":data.field.expect_treat_affect,
                        "apparatus_brand":data.field.apparatus_brand,
                        "apparatus_name":data.field.apparatus_name,
                        "apparatus_num":data.field.apparatus_num,
                        "bad_event_main_declare":data.field.bad_event_main_declare,
                        "event_happen_time":data.field.event_happen_time,
                        "reporter_know_time":data.field.reporter_know_time,
                        "bad_event_ending":data.field.bad_event_ending,
                        "status":2 //递交
                    },
                    success:function () {
                        layer.msg("提交成功");
                        form.val("FormLoad",{
                            "report_date":null,
                            "report_source":null,
                            "patient_name":null,
                            "patient_age":null,
                            "patient_sex":null,
                            "expect_treat_affect":null,
                            "apparatus_brand":null,
                            "apparatus_name":null,
                            "apparatus_num":null,
                            "bad_event_main_declare":null,
                            "event_happen_time":null,
                            "reporter_know_time":null,
                            "bad_event_ending":null,
                        })
                        form.render();
                    },
                })

            }, function () {
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        //save 保存事件监听
        form.on('submit(save)', function(data) {
            $.ajax({
                url: '/event/event_insert',
                type: "POST",
                data:{
                    "reporter_code":layui.data('user').userinfo.user_code,
                    "reporter_name":layui.data('user').userinfo.user_name,
                    "dept_code":layui.data('user').userinfo.dept_code,
                    "dept_name":layui.data('user').userinfo.dept_name,
                    "event_code":6,
                    "report_date":data.field.report_date,
                    "report_source":data.field.report_source,
                    "reporter":data.field.reporter,
                    "reporter_department":data.field.reporter_department,
                    "patient_name":data.field.patient_name,
                    "patient_age":data.field.patient_age,
                    "patient_sex":data.field.patient_sex,
                    "expect_treat_affect":data.field.expect_treat_affect,
                    "apparatus_brand":data.field.apparatus_brand,
                    "apparatus_name":data.field.apparatus_name,
                    "apparatus_num":data.field.apparatus_num,
                    "bad_event_main_declare":data.field.bad_event_main_declare,
                    "event_happen_time":data.field.event_happen_time,
                    "reporter_know_time":data.field.reporter_know_time,
                    "bad_event_ending":data.field.bad_event_ending,
                    "status": 1//1表示保存，可修改
                },
                success:function () {
                    layer.msg("保存成功");
                    form.val("FormLoad",{
                        "report_date":null,
                        "report_source":null,
                        "patient_name":null,
                        "patient_age":null,
                        "patient_sex":null,
                        "expect_treat_affect":null,
                        "apparatus_brand":null,
                        "apparatus_name":null,
                        "apparatus_num":null,
                        "bad_event_main_declare":null,
                        "event_happen_time":null,
                        "reporter_know_time":null,
                        "bad_event_ending":null,
                    })
                    form.render();
                },
            });
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    })
</script>

</html>